import DataItemModel from "../../../cfw/mvc/DataItemModel";
import { CristmasLightModelEnum } from "../../../public/GameEnumConfig";
import User from "../../db/User";
import { ItemState } from "../../../cfw/tools/Define";
import Player from "../../player/Player";
/**
* 圣诞树灯
**/
export default class CristmasLightModel extends DataItemModel {

	static CLASS_NAME: string = 'CristmasLightModel'


	init(id, data) {
		super.init(id, data)
		this.state = User.instance().getLightState(this.ID)
	}

	setState(s) {
		super.setState(s)
		User.instance().setLightState(this.ID, s)
	}

	getOpenLevel() {
		let num = this.data[CristmasLightModelEnum.adge]
		return num ? num : 0
	}
	
	isOpen() {
		return Player.instance().getLevel() >= this.getOpenLevel();
	}
	needBuy() {
		let cost: number[] = this.getCostItem()
		return cost && cost.length > 0 && this.getState() != ItemState.GOT
	}

	// icon
	getIcon() {
		return 'texture/cristmas/' + this.data[CristmasLightModelEnum.icon]
	}
	// 使用道具
	getSprite() {
		return 'texture/lights/' + this.data[CristmasLightModelEnum.sprite]
	}
	// 消费道具
	getCostItem() {
		return this.data[CristmasLightModelEnum.costItem]
	}


	use() {
		User.instance().setLightID(this.ID)
	}

	unuse() {
		User.instance().setLightID(0)
	}


}